package b.f;

/* compiled from: LongSparseArray */
public class e<E> implements Cloneable {
    public static final Object e = new Object();
    public boolean a;
    public long[] b;
    public Object[] c;
    public int d;

    public e() {
        this(10);
    }

    public void a(long j, E e) {
        int i = this.d;
        if (i == 0 || j > this.b[i - 1]) {
            if (this.a && i >= this.b.length) {
                d();
            }
            i = this.d;
            if (i >= this.b.length) {
                int f = d.f(i + 1);
                long[] jArr = new long[f];
                Object[] objArr = new Object[f];
                long[] jArr2 = this.b;
                System.arraycopy(jArr2, 0, jArr, 0, jArr2.length);
                Object[] objArr2 = this.c;
                System.arraycopy(objArr2, 0, objArr, 0, objArr2.length);
                this.b = jArr;
                this.c = objArr;
            }
            this.b[i] = j;
            this.c[i] = e;
            this.d = i + 1;
            return;
        }
        h(j, e);
    }

    public void b() {
        int i = this.d;
        Object[] objArr = this.c;
        for (int i2 = 0; i2 < i; i2++) {
            objArr[i2] = null;
        }
        this.d = 0;
        this.a = false;
    }

    /* renamed from: c */
    public e<E> clone() {
        try {
            e eVar = (e) super.clone();
            eVar.b = (long[]) this.b.clone();
            eVar.c = (Object[]) this.c.clone();
            return eVar;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError(e);
        }
    }

    public final void d() {
        int i = this.d;
        long[] jArr = this.b;
        Object[] objArr = this.c;
        int i2 = 0;
        for (int i3 = 0; i3 < i; i3++) {
            Object obj = objArr[i3];
            if (obj != e) {
                if (i3 != i2) {
                    jArr[i2] = jArr[i3];
                    objArr[i2] = obj;
                    objArr[i3] = null;
                }
                i2++;
            }
        }
        this.a = false;
        this.d = i2;
    }

    public E e(long j) {
        return f(j, null);
    }

    public E f(long j, E e) {
        int b = d.b(this.b, this.d, j);
        if (b >= 0) {
            Object[] objArr = this.c;
            if (objArr[b] != e) {
                return objArr[b];
            }
        }
        return e;
    }

    public long g(int i) {
        if (this.a) {
            d();
        }
        return this.b[i];
    }

    public void h(long j, E e) {
        int b = d.b(this.b, this.d, j);
        if (b >= 0) {
            this.c[b] = e;
        } else {
            long[] jArr;
            Object[] objArr;
            b = ~b;
            int i = this.d;
            if (b < i) {
                Object[] objArr2 = this.c;
                if (objArr2[b] == e) {
                    this.b[b] = j;
                    objArr2[b] = e;
                    return;
                }
            }
            if (this.a && i >= this.b.length) {
                d();
                b = ~d.b(this.b, this.d, j);
            }
            i = this.d;
            if (i >= this.b.length) {
                i = d.f(i + 1);
                jArr = new long[i];
                objArr = new Object[i];
                long[] jArr2 = this.b;
                System.arraycopy(jArr2, 0, jArr, 0, jArr2.length);
                Object[] objArr3 = this.c;
                System.arraycopy(objArr3, 0, objArr, 0, objArr3.length);
                this.b = jArr;
                this.c = objArr;
            }
            i = this.d;
            if (i - b != 0) {
                jArr = this.b;
                int i2 = b + 1;
                System.arraycopy(jArr, b, jArr, i2, i - b);
                objArr = this.c;
                System.arraycopy(objArr, b, objArr, i2, this.d - b);
            }
            this.b[b] = j;
            this.c[b] = e;
            this.d++;
        }
    }

    public int i() {
        if (this.a) {
            d();
        }
        return this.d;
    }

    public E j(int i) {
        if (this.a) {
            d();
        }
        return this.c[i];
    }

    public String toString() {
        if (i() <= 0) {
            return "{}";
        }
        StringBuilder stringBuilder = new StringBuilder(this.d * 28);
        stringBuilder.append('{');
        for (int i = 0; i < this.d; i++) {
            if (i > 0) {
                stringBuilder.append(", ");
            }
            stringBuilder.append(g(i));
            stringBuilder.append('=');
            e j = j(i);
            if (j != this) {
                stringBuilder.append(j);
            } else {
                stringBuilder.append("(this Map)");
            }
        }
        stringBuilder.append('}');
        return stringBuilder.toString();
    }

    public e(int i) {
        this.a = false;
        if (i == 0) {
            this.b = d.b;
            this.c = d.c;
            return;
        }
        i = d.f(i);
        this.b = new long[i];
        this.c = new Object[i];
    }
}
